package com.hongxun.modules.eys.service.impl;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.hongxun.modules.eys.dao.EWorkContentDao;
import com.hongxun.modules.eys.entity.EWorkContentEntity;
import com.hongxun.modules.eys.service.EWorkContentService;


@Service("eWorkContentService")
public class EWorkContentServiceImpl implements EWorkContentService {
    @Autowired
    private EWorkContentDao eWorkContentDao;

    @Override
    public EWorkContentEntity queryObject(String guid) {
        return eWorkContentDao.queryObject(guid);
    }

    @Override
    public List<EWorkContentEntity> queryList(Map<String, Object> map) {
        return eWorkContentDao.queryList(map);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return eWorkContentDao.queryTotal(map);
    }

    @Override
    public void save(EWorkContentEntity eWorkContent) {
        if (eWorkContent.getGuid() == null || eWorkContent.getGuid().equals("")) {

            eWorkContent.setGuid(UUID.randomUUID().toString());
        }
        eWorkContentDao.save(eWorkContent);
    }

    @Override
    public void update(EWorkContentEntity eWorkContent) {
        eWorkContentDao.update(eWorkContent);
    }

    @Override
    public void delete(String guid) {
        eWorkContentDao.delete(guid);
    }

    @Override
    public void deleteBatch(String[] guids) {
        eWorkContentDao.deleteBatch(guids);
    }

    @Override
    public void insertOrReplaceOrDelete(List<EWorkContentEntity> entities) {
        for (EWorkContentEntity d : entities) {
            if (d.getWCDatastate().equals("删除")) {
                eWorkContentDao.delete(d.getGuid());
            } else {
                EWorkContentEntity eCrossCostEntity = eWorkContentDao.queryObject(d.getGuid());
                if (eCrossCostEntity == null) {
                    eWorkContentDao.save(d);
                } else {
                    eWorkContentDao.update(d);
                }
            }
        }
    }

}
